<?php

/*
 *
 * @authors : IT123编程社区-mastudy
 * @email  :admin@it123.org
 * @bbs http://www.it123.org
 *  @link http://www.it123.org
 *  @Powered By  ©2016 www.it123.org[IT123编程社区]
 */

// 本类由系统自动生成，仅供测试用途
class MemberAction extends CommonUserAction {

        public function index() {


                //     $uid = ToolsAction::checkLogin();
                //    $numccount = ToolsAction::getUserCcountInfo($uid);
                //       $this->assign('ccount_points', $numccount);



                cookie('LURL', __SELF__);


                $this->display();
        }

        public function editVideoSubjectDo() {



                $uid = ToolsAction::checkLogin();




                $subject_aid = $this->_post('subject_aid');
                $subject_title = $this->_post('subject_title');
                $subject_desc = $this->_post('editorValue');


                if (!is_numeric($subject_aid)) {

                        $this->error('参数错误！');
                }


                if (!$subject_title) {

                        $this->error('专辑名称要填写下！');
                }

                if (!$subject_desc) {

                        $this->error('专辑简介要填写下！');
                }



                $data['subject_id'] = $subject_aid;

                $data['subject_title'] = $subject_title;

                $data['subject_desc'] = $subject_desc;

                $data['subject_author'] = $uid;
                $data['subject_time'] = time();







                $vsubjectDB = M('video_subject');



                if ($vsubjectDB->save($data) !== FALSE) {



                        $this->success('OK', __URL__ . '/manageVideoSubject/');
                } else {

                        $this->sorry('sorry');
                }
        }

        public function upModuleContentPic() {

                $item_id = $this->_get('item');
                $module_name = $this->_get('module');

                if (!is_numeric($item_id)) {

                        die('参数错误');
                }




                import('ORG.Net.UploadFile');
                $upload = new UploadFile(); // 实例化上传类


                $upload->zipImages = TRUE; // 压缩图片文件上传

                $upload->thumbType = 0; // 压缩图片文件上传
                $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型


                $upload->autoSub = FALSE;


                $upload->thumb = true;
                $upload->thumbMaxWidth = '800';
                $upload->thumbMaxHeight = '2000';

                $upload->thumbPrefix = '_';

                $upload->thumbRemoveOrigin = TRUE;

                $upload->savePath = './Data/Uploads/' . $module_name . '/'; // 设置附件上传目录

                $upload->saveRule = 'AC' . $item_id . '_' . date('YmdHis') . '_' . rand(000, 999); //保存文件名


                if ($upload->upload()) {
                        $info = $upload->getUploadFileInfo();

                        echo json_encode(array(
                            'url' => __ROOT__ . substr($info[0]['savepath'], 1) . '_' . $info[0]['savename'],
                            //    'url' => '/Data/Uploads/Article/AC'.$info[0]['savename'],
                            'title' => htmlspecialchars('www.it123.org网站' . $module_name . '模块的项目' . $item_id . '的图片'),
                            'original' => htmlspecialchars('www.it123.org网站' . $module_name . '模块的项目' . $item_id . '的图片'),
                            'state' => 'SUCCESS'
                        ));
                } else {
                        echo json_encode(array(
                            'state' => $upload->getErrorMsg()
                        ));
                }
        }

        public function upContentPic() {

                $id = $this->_get('id');

                $module = $this->_get('module');



                import('ORG.Net.UploadFile');
                $upload = new UploadFile(); // 实例化上传类


                $upload->zipImages = TRUE; // 压缩图片文件上传

                $upload->thumbType = 0; // 压缩图片文件上传
                $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型


                $upload->autoSub = FALSE;


                $upload->thumb = true;
                $upload->thumbMaxWidth = '800';
                $upload->thumbMaxHeight = '2000';

                $upload->thumbPrefix = '_';

                $upload->thumbRemoveOrigin = TRUE;

                $upload->savePath = './Data/Uploads/' . $module . '/'; // 设置附件上传目录

                $upload->saveRule = 'AC' . $id . '_' . date('YmdHis') . '_' . rand(000, 999); //保存文件名


                if ($upload->upload()) {
                        $info = $upload->getUploadFileInfo();

                        echo json_encode(array(
                            'url' => __ROOT__ . substr($info[0]['savepath'], 1) . '_' . $info[0]['savename'],
                            'title' => htmlspecialchars('www.it123.org' . $module . $id . '图片'),
                            'original' => htmlspecialchars('www.it123.org' . $module . $id . '图片'),
                            'state' => 'SUCCESS'
                        ));
                } else {
                        echo json_encode(array(
                            'state' => $upload->getErrorMsg()
                        ));
                }
        }

        public function upArticlePic() {

                $id = $this->_get('id');





                import('ORG.Net.UploadFile');
                $upload = new UploadFile(); // 实例化上传类


                $upload->zipImages = TRUE; // 压缩图片文件上传

                $upload->thumbType = 0; // 压缩图片文件上传
                $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型


                $upload->autoSub = FALSE;


                $upload->thumb = true;
                $upload->thumbMaxWidth = '800';
                $upload->thumbMaxHeight = '2000';

                $upload->thumbPrefix = '_';

                $upload->thumbRemoveOrigin = TRUE;

                $upload->savePath = './Data/Uploads/Article/'; // 设置附件上传目录

                $upload->saveRule = 'AC' . $id . '_' . date('YmdHis') . '_' . rand(000, 999); //保存文件名


                if ($upload->upload()) {
                        $info = $upload->getUploadFileInfo();

                        echo json_encode(array(
                            'url' => __ROOT__ . substr($info[0]['savepath'], 1) . '_' . $info[0]['savename'],
                            //    'url' => '/Data/Uploads/Article/AC'.$info[0]['savename'],
                            'title' => htmlspecialchars('www.it123.org文章' . $id . '图片'),
                            'original' => htmlspecialchars('www.it123.org文章' . $id . '图片'),
                            'state' => 'SUCCESS'
                        ));
                } else {
                        echo json_encode(array(
                            'state' => $upload->getErrorMsg()
                        ));
                }
        }

        public function previewArticle() {

                $aid = $this->_get('aid');


                if (!is_numeric($aid)) {
                        $this->error('error');
                }

                $aDB = M('article');

                $where['article_id'] = $aid;





                $data = $aDB->where($where)->find();



                if (!$data) {
                        $this->error('没有数据');
                }

                $uid = session('member.member_id');


                if ($data['article_author_id'] != $uid && session('member.member_type') > 1) {

                        $this->error('您没有权限查看');
                }








                $data['article_auther'] = ToolsAction::getUserinfo($data['article_author_id'], 'member_nickname');

                $data['article_title'] = htmlspecialchars_decode($data['article_title']);
                $data['article_desc'] = htmlspecialchars_decode($data['article_desc']);

                $data['article_content'] = htmlspecialchars_decode($data['article_content']);

                $data['article_read_level'] = $data['article_read_level'];

                $data['article_visits'] = $data['article_visits'];
                $data['article_addtime'] = date('Y-m-d', $data['article_addtime']);




                $tags = ToolsAction::gettags($data['article_id'], 1);




                $this->assign('article', $data);


                $this->assign('likeNO', $this->getlikeNumber(1, $data['article_id']));





                $this->assign('tags_list', $tags);


                $this->assign('hotTags', $this->hotTags());

                $this->assign('getNewArt', $this->getNewArt());

                $this->assign('hotArticle', $this->getHotArt());





                $this->display();
        }

        public function upBookThumbnail() {





                $aid = session('book_aid');



                import('ORG.Net.UploadFile');
                $upload = new UploadFile(); // 实例化上传类
                $upload->maxSize = 3145728; // 设置附件上传大小
                $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg', 'PNG',); // 设置附件上传类型


                $upload->zipImages = TRUE; // 压缩图片文件上传
                $upload->thumb = TRUE; //生成缩略图
                $upload->thumbRemoveOrigin = true; //删除原图

                $upload->thumbMaxWidth = '390'; //缩略图宽度
                $upload->thumbMaxHeight = '543'; //缩略图高度
                $upload->thumbPrefix = 'Thumb_'; //缩略图高度

                $upload->saveRule = $aid; //保存文件名


                $upload->savePath = './Data/Uploads/Book/';




                if (!$upload->upload()) {// 上传错误提示错误信息
                        $this->error($upload->getErrorMsg());
                } else {// 上传成功 获取上传文件信息
                        $info = $upload->getUploadFileInfo();
                }


                $bookDB = M('book');

                $data['book_id'] = $aid;
                $data['book_thumb'] = 'Thumb_' . $info[0]['savename'];
                $bookDB->save($data);

                die(json_encode(array('url' => __ROOT__ . '/Data/Uploads/Book/' . 'Thumb_' . $info[0]['savename'])));
                die(1);
        }

        public function upItemThumbnail() {





                $aid = session('item_aid');



                import('ORG.Net.UploadFile');
                $upload = new UploadFile(); // 实例化上传类
                $upload->maxSize = 3145728; // 设置附件上传大小
                $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg', 'PNG',); // 设置附件上传类型


                $upload->zipImages = TRUE; // 压缩图片文件上传
                $upload->thumb = TRUE; //生成缩略图
                $upload->thumbRemoveOrigin = true; //删除原图

                $upload->thumbMaxWidth = '500'; //缩略图宽度
                $upload->thumbMaxHeight = '300'; //缩略图高度
                $upload->thumbPrefix = 'Thumb_'; //缩略图高度

                $upload->saveRule = $aid; //保存文件名


                $upload->savePath = './Data/Uploads/Item/';




                if (!$upload->upload()) {// 上传错误提示错误信息
                        $this->error($upload->getErrorMsg());
                } else {// 上传成功 获取上传文件信息
                        $info = $upload->getUploadFileInfo();
                }


                $artDB = M('item');

                $data['item_id'] = $aid;
                $data['item_thumb'] = 'Thumb_' . $info[0]['savename'];
                $artDB->save($data);

                die(json_encode(array('url' => __ROOT__ . '/Data/Uploads/Item/' . 'Thumb_' . $info[0]['savename'])));
                die(1);
        }

        public function upArtThumb() {


                $aid = $this->_get('id');


                if (!is_numeric($aid)) {

                        die(json_encode(array('msg' => '参数错误')));
                }



                import('ORG.Net.UploadFile');
                $upload = new UploadFile(); // 实例化上传类
                $upload->maxSize = 3145728; // 设置附件上传大小
                $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg', 'PNG',); // 设置附件上传类型


                $upload->zipImages = TRUE; // 压缩图片文件上传
                $upload->thumb = TRUE; //生成缩略图
                $upload->thumbRemoveOrigin = true; //删除原图

                $upload->thumbMaxWidth = '400'; //缩略图宽度
                $upload->thumbMaxHeight = '300'; //缩略图高度
                $upload->thumbPrefix = 'Thumb_'; //缩略图高度



                $upload->saveRule = $aid; //保存文件名


                $upload->savePath = './Data/Uploads/Article/';



                if (!$upload->upload()) {// 上传错误提示错误信息
                        $this->error($upload->getErrorMsg());
                } else {// 上传成功 获取上传文件信息
                        $info = $upload->getUploadFileInfo();
                }


                $artDB = M('article');

                $data['article_id'] = $aid;
                $data['article_thumb'] = 'Thumb_' . $info[0]['savename'];



                $artDB->save($data);

                die(json_encode(array('url' => __ROOT__ . '/Data/Uploads/Article/' . 'Thumb_' . $info[0]['savename'])));
                die(1);
        }

        public function upSubjectThumbnail() {




                import('ORG.Net.UploadFile');
                $upload = new UploadFile(); // 实例化上传类
                $upload->maxSize = 3145728; // 设置附件上传大小
                $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg', 'PNG',); // 设置附件上传类型


                $upload->zipImages = TRUE; // 压缩图片文件上传
                $upload->thumb = TRUE; //生成缩略图
                $upload->thumbRemoveOrigin = true; //删除原图

                $upload->thumbMaxWidth = '500'; //缩略图宽度
                $upload->thumbMaxHeight = '300'; //缩略图高度
                $upload->thumbPrefix = 'Thumb_'; //缩略图高度

                $aid = session('subject_aid');
                $upload->saveRule = $aid; //保存文件名


                $upload->savePath = './Data/Uploads/Subject/';




                if (!$upload->upload()) {// 上传错误提示错误信息
                        $this->error($upload->getErrorMsg());
                } else {// 上传成功 获取上传文件信息
                        $info = $upload->getUploadFileInfo();
                }


                $artDB = M('subject');

                $data['subject_id'] = $aid;
                $data['subject_thumb'] = 'Thumb_' . $info[0]['savename'];
                $artDB->save($data);

                die(json_encode(array('url' => __ROOT__ . '/Data/Uploads/Subject/' . 'Thumb_' . $info[0]['savename'])));
                die(1);
        }

        public function ajaxUpdateNickName() {

                $nickname = $this->_post('nickname');


                if ($nickname == session('member.member_nickname')) {
                        die(json_encode(array('status' => 2)));
                }


                if ($nickname == NULL || !session('member')) {
                        die(json_encode(array('status' => FALSE)));
                }



                $mDB = M('member_basic');
                $where_nickname['member_nickname'] = $nickname;

                $tempuser = $mDB->where($where_nickname)->find();

                if ($tempuser) {

//昵称被占用
                        die(json_encode(array('status' => -2)));
                }

                $uid = session('member.member_id');


                $data['member_id'] = $uid;
                $data['member_nickname'] = $nickname;

                if ($mDB->save($data)) {

                        $where['member_id'] = $uid;


                        $member_info = $mDB->where($where)->find();

                        session('member', $member_info);


                        die(json_encode(array('status' => TRUE)));
                } else {
                        die(json_encode(array('status' => FALSE)));
                }
        }

        public function ajaxUpdateTopicVerifystatus() {


                $id = $this->_post('id');

                $topicDB = M('group_topic');


                $where['topic_id'] = $id;


                $info = $topicDB->where($where)->find();


                if (!$info) {

                        die(json_encode(array('status' => -1)));
                }

                if ($info['topic_verifystatus'] == 0) {



                        if ($topicDB->where($where)->setField('topic_verifystatus', 1)) {



                                die(json_encode(array('status' => TRUE)));
                        } else {
                                die(json_encode(array('status' => FALSE)));
                        }
                } else if ($info['topic_verifystatus'] == 1) {



                        if ($topicDB->where($where)->setField('topic_verifystatus', 2)) {
                                die(json_encode(array('status' => TRUE)));
                        } else {
                                die(json_encode(array('status' => FALSE)));
                        }
                } else if ($info['topic_verifystatus'] == 2) {



                        if ($topicDB->where($where)->setField('topic_verifystatus', 0)) {
                                die(json_encode(array('status' => TRUE)));
                        } else {
                                die(json_encode(array('status' => FALSE)));
                        }
                }
        }

        public function ajaxUpdateFlinkVerifystatus() {


                $id = $this->_post('id');

                $fDB = M('flink');


                $where['flink_id'] = $id;


                $info = $fDB->where($where)->find();


                if (!$info) {

                        die(json_encode(array('status' => -1)));
                }

                if ($info['flink_verifystatus'] == 0) {



                        if ($fDB->where($where)->setField('flink_verifystatus', 1)) {



                                die(json_encode(array('status' => TRUE)));
                        } else {
                                die(json_encode(array('status' => FALSE)));
                        }
                } else if ($info['flink_verifystatus'] == 1) {



                        if ($fDB->where($where)->setField('flink_verifystatus', 2)) {
                                die(json_encode(array('status' => TRUE)));
                        } else {
                                die(json_encode(array('status' => FALSE)));
                        }
                } else if ($info['flink_verifystatus'] == 2) {



                        if ($fDB->where($where)->setField('flink_verifystatus', 0)) {
                                die(json_encode(array('status' => TRUE)));
                        } else {
                                die(json_encode(array('status' => FALSE)));
                        }
                }
        }

        public function ajaxUpdateMembertype() {

                $this->setRight(1);



                if (!IS_AJAX) {

                        die(json_encode(array('status' => -1)));
                }


                $uid = $this->_post('uid');

                $type = $this->_post('type');



                if (!is_numeric($uid) || !is_numeric($type)) {

                        die(json_encode(array('status' => -1)));
                }

                $mDB = M('member_basic');

                $data['member_id'] = $uid;
                $data['member_type'] = $type;
                $res = $mDB->save($data);
                if ($res !== FALSE) {
                        die(json_encode(array('status' => TRUE)));
                } else {
                        die(json_encode(array('status' => FALSE)));
                }
        }

        public function addArticle() {

                $uid = session('member.member_id');













// 第一步：查找空专辑继续编辑

                $articleDB = M('article');


                $where['article_title'] = '';


                $where['article_author_id'] = $uid;


                $artinfo = $articleDB->where($where)->find();

                if ($artinfo) {

                        $article_aid = $artinfo['article_id'];
                } else {







                        $adata_article['article_uid'] = $uid;

                        $adata_article['article_time'] = time();



                        $article_aid = $articleDB->add($adata_article);

                        if (!$article_aid) {
                                $this->error('请重试！');
                        }
                }


                session('article_aid', $article_aid);









                $this->assign('article_aid', $article_aid);




                $this->display();
        }

        public function manageArticle() {


                $uid = ToolsAction::checkLogin();

                $articleDB = M('article');



                $where['article_uid'] = $uid;
                $where['article_title'] = array('not in', '');



                import('ORG.Util.Page'); // 导入分页类
                $count = $articleDB->where($where)->count(); // 查询满足要求的总记录数
                $Page = new Page($count, 10); // 实例化分页类 传入总记录数和每页显示的记录数
                $show = $Page->show(); // 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
                $list = $articleDB->where($where)->order('article_time desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();




                $list = ToolsAction::resetArticleList($list);








                $this->assign('list', $list); // 赋值数据集
                $this->assign('page', $show); // 赋值分页输出







                $this->display();
        }

        public function editArticle() {

                $id = $this->_get('id');

                if (!is_numeric($id)) {
                        $this->error('非法操作！');
                }


                $articleDB = M('article');


                $where['article_id'] = $id;

                $article = $articleDB->where($where)->find();



                if (!$article) {

                        $this->error('参数错误！');
                }




                $article['article_title'] = htmlspecialchars_decode($article['article_title']);
                $article['article_desc'] = htmlspecialchars_decode($article['article_desc']);
                $article['article_text'] = htmlspecialchars_decode($article['article_text']);
                $article['tags'] = ToolsAction::gettags($article['article_id'], 1);
                
                
                

                $article['article_thumb'] = ToolsAction::getArticleThumb($article['article_id']);


                $article['tags'] = implode('#', $article['tags']);



  


                $this->assign('article', $article);



                $this->display();
        }

        public function editArticleDo() {



                $uid = ToolsAction::checkLogin();







                $id = $this->_post('article_aid');


                //$article_price = $this->_post('article_price');



                $title = $this->_post('title');


                $content = $this->_post('editorValue');


                $desc = $this->_post('description');

                $tags = $_POST['tags'];


                if (!$tags) {

                        $this->error('标签必须填写！');
                }


                if (!isset($title) || !isset($content)) {

                        $this->error('请填写选项');
                }




                $title = ToolsAction::cleanhtml(htmlspecialchars_decode($title));



//处理desc
                if (isset($desc)) {

                        $desc = htmlspecialchars($desc);
                } else {

                        $desc = htmlspecialchars_decode($content);


                        $desc = mb_substr($desc, 0, 400, 'UTF-8');
                }




                $aDB = M('article');

                $data['article_id'] = $id;
                $data['article_title'] = $title;

                $data['article_desc'] = $desc;
                $data['article_text'] = $content;

                $data['article_uid'] = $uid;

                $data['article_time'] = time();

                if ($aDB->save($data)) {






                        if (isset($tags)) {


                                $del_count = M('tags')->where(array('tags_item_id' => $id, 'tags_module_id' => 1))->delete();




                                if (ToolsAction::addTags($id, 1, $tags)) {

                                        $this->success('ok', '__APP__/Member/manageArticle/');
                                } else {
                                        $this->success('标签发布失败', '__APP__/Member/manageArticle/');
                                }
                        } else {
                                $this->success('ok');
                        }
                } else {
                        $this->error('失败!');
                }
        }

        public function LoginRecord() {




                $loginrecordsDB = M('user_loginrecords');


                $list = $loginrecordsDB->select();



                $this->assign('list', $list);


                $this->display();
        }

        public function cleanhtmlshow() {






                $id = $this->_get('id');





                $statis_file = APP_PATH . 'html/Article/' . $id . '.html';

                if (!file_exists($statis_file) || (time() - filemtime($statis_file)) > 60 * 60 * 24) {



                        $aDB = M('article');

                        $where['article_id'] = $id;

                        $data = $aDB->where($where)->find();

                        if (!$data) {
                                $this->error('数据不存在');
                        }




                        $data['title'] = ToolsAction::decode_do($data['article_title']);
                        $data['content'] = ToolsAction::decode_do($data['article_content']);




                        $this->assign('title', $data['title']);


                        $this->assign('content', $data['content']);


                        $this->buildHtml('/Article/' . $id, '', 'show');
                }

//echo file_get_contents($statis_file);//输出静态文件内容



                redirect(__ROOT__ . '/Pc/html/Article/' . $id . '.html');
        }

        public function managetags() {


                $this->setRight(1);
                import('ORG.Util.Page'); // 导入分页类



                $tagsDB = M('tags');




                $count = $tagsDB->count(); // 查询满足要求的总记录数
                $Page = new Page($count, 10); // 实例化分页类 传入总记录数和每页显示的记录数
                $show = $Page->show(); // 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
                $data = $tagsDB->limit($Page->firstRow . ',' . $Page->listRows)->select();

                $this->assign('list', $data);


                $this->assign('page', $show);
                $this->display();
        }

        public function payimg() {





                $uid = ToolsAction::checkLogin();


                $alipayimg = ToolsAction::getUserAlpayimg($uid);

                $wxpayimg = ToolsAction::getUserWxpayimg($uid);



                $this->assign('alipayimg', $alipayimg);


                $this->assign('wxpayimg', $wxpayimg);


                $this->display();
        }

        public function updateface() {






                $this->display();
        }

}
